package yuejian_07.yuejian_07.model;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import yuejian_07.yuejian_07.RetrofitListener;
import yuejian_07.yuejian_07.base.RetrofitListenerTow;
import yuejian_07.yuejian_07.javabean.Train;
import yuejian_07.yuejian_07.javabean.TrainOrder;
import yuejian_07.yuejian_07.service.TrainService;

/**
 * Created by dell on 2017/10/11.
 */

public class TrainModel {
    private Retrofit retrofit;

    public TrainModel() {
        retrofit = new Retrofit.Builder()
                .baseUrl("http://10.0.2.2/neu1_yuejian/index.php/Api/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }

    /*获取活动列表*/
    public void trainlist(final RetrofitListener listener) {
        TrainService trainService = retrofit.create(TrainService.class);
        Call call = trainService.getAllTrains();
        Callback<List<Train>> callback = new Callback<List<Train>>() {
            @Override
            public void onResponse(Call<List<Train>> call, Response<List<Train>> response) {
                List<Train> data = response.body();
                listener.onSuccess(data);//userId这里有问题
            }

            @Override
            public void onFailure(Call<List<Train>> call, Throwable t) {
                listener.onFail();
            }
        };
        call.enqueue(callback);
    }

    /*获取菜鸟列表*/
    public void caijilist(final RetrofitListener listener) {
        TrainService trainService = retrofit.create(TrainService.class);
        Call call = trainService.getCaijiTrain();
        Callback<List<Train>> callback = new Callback<List<Train>>() {
            @Override
            public void onResponse(Call<List<Train>> call, Response<List<Train>> response) {
                List<Train> data = response.body();
                listener.onSuccess(data);//userId这里有问题
            }

            @Override
            public void onFailure(Call<List<Train>> call, Throwable t) {
                listener.onFail();
            }
        };
        call.enqueue(callback);
    }

    /*获取进阶列表*/
    public void jinjielist(final RetrofitListener listener) {
        TrainService trainService = retrofit.create(TrainService.class);
        Call call = trainService.getJinjieTrain();
        Callback<List<Train>> callback = new Callback<List<Train>>() {
            @Override
            public void onResponse(Call<List<Train>> call, Response<List<Train>> response) {
                List<Train> data = response.body();
                listener.onSuccess(data);//userId这里有问题
            }

            @Override
            public void onFailure(Call<List<Train>> call, Throwable t) {
                listener.onFail();
            }
        };
        call.enqueue(callback);
    }

    /*获取高手列表*/
    public void gaoshoulist(final RetrofitListener listener) {
        TrainService trainService = retrofit.create(TrainService.class);
        Call call = trainService.getGaoshouTrain();
        Callback<List<Train>> callback = new Callback<List<Train>>() {
            @Override
            public void onResponse(Call<List<Train>> call, Response<List<Train>> response) {
                List<Train> data = response.body();
                listener.onSuccess(data);//userId这里有问题
            }

            @Override
            public void onFailure(Call<List<Train>> call, Throwable t) {
                listener.onFail();
            }
        };
        call.enqueue(callback);
    }


    //获取培训详情
    public void getTrainById(int Train_id, final RetrofitListener listener){
        TrainService trainService=retrofit.create(TrainService.class);
        Call call=trainService.getTrainById(Train_id);
        Callback<Train> callback=new Callback<Train>(){
            @Override
            public void onResponse(Call<Train> call, Response<Train> response){

                listener.onSuccess(response.body());
            }
            @Override
            public void onFailure(Call<Train> call,Throwable t){
                t.printStackTrace();
                listener.onFail();
            }
        };
        call.enqueue(callback);
    }
<<<<<<< HEAD


    public void getTrainBySearch(String SearchKey, final RetrofitListener listener){
        TrainService trainService=retrofit.create(TrainService.class);
        Call call=trainService.getTrainBySearch(SearchKey);
        Callback<List<Train>> callback=new Callback<List<Train>>(){
            @Override
            public void onResponse(Call<List<Train>> call, Response<List<Train>> response ){
                List<Train> data=response.body();
                listener.onSuccess(data);//userId这里有问题
            }
            @Override
            public  void onFailure(Call<List<Train>> call, Throwable t){
                listener.onFail();
=======
    //活动下订单
    public void insertOrder(int user_id,int train_id, final RetrofitListenerTow listener){
        TrainService trainService=retrofit.create(TrainService.class);
        Call call=trainService.insertOrder(user_id,train_id);
        Callback<TrainOrder> callback=new Callback<TrainOrder>(){
            @Override
            public void onResponse(Call<TrainOrder> call, Response<TrainOrder> response ){
                TrainOrder data=response.body();
                listener.onSuccessTow(data);
            }
            @Override
            public  void onFailure(Call<TrainOrder> call, Throwable t){
                listener.onFailTow();
>>>>>>> 9cbb853725830abfea6e866ce1cbf3c925de3bcd
            }
        };
        call.enqueue(callback);
    }
<<<<<<< HEAD

=======
>>>>>>> 9cbb853725830abfea6e866ce1cbf3c925de3bcd
}
